//
//  HZJViewController.swift
//  HZJTreeView
//
//  Created by 何治军 on 2020/6/18.
//  Copyright © 2020 何治军. All rights reserved.
//

import UIKit

class HZJViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = .gray
        self.view.addSubview(tabV)
        tabV.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        self.tabV.setHeader({
            let v = UILabel(frame: CGRect(x: 0, y: 0, width: 400, height: 50))
            v.text = "头"
            v.textAlignment = .center
            v.backgroundColor = .orange
            return v
        }())
        setInfo()
        self.tabV.setFooter({
            let v = UILabel(frame: CGRect(x: 0, y: 0, width: 400, height: 100))
            v.text = "底部"
            v.textAlignment = .center
            v.backgroundColor = .brown
            return v
        }())
    }
    
    lazy var tabV: HZJTreeTab = {
        let v = HZJTreeTab()
        return v
    }()
    
    
    func setInfo() {
        let model11 = HZJTreeModel("model11")
        let model12 = HZJTreeModel("model12")
        let model13 = HZJTreeModel("model13")
        let model14 = HZJTreeModel("model14")
        let model15 = HZJTreeModel("model15")
        
        let model51 = HZJTreeModel("model51")
        let model52 = HZJTreeModel("model52")
        let model53 = HZJTreeModel("model53")
        let model54 = HZJTreeModel("model54")
        let model55 = HZJTreeModel("model55")
        let model56 = HZJTreeModel("model56")
        let model57 = HZJTreeModel("model57")
        let model58 = HZJTreeModel("model58")
        let model59 = HZJTreeModel("model59")
        
        model52.setChildModels([model51])
        model53.setChildModels([model52])
        model54.setChildModels([model53])
        model55.setChildModels([model54])
        model56.setChildModels([model55])
        model57.setChildModels([model56])
        model58.setChildModels([model57])
        model59.setChildModels([model58])

        model11.setChildModels([model59])

        let model21 = HZJTreeModel("model21").setOpenState(true)
        let model22 = HZJTreeModel("model22")

        let model31 = HZJTreeModel("model31").setOpenState(true)
        let model32 = HZJTreeModel("model32")
        let model33 = HZJTreeModel("model33").setOpenState(true)
        
        model21.setChildModels([model11,model12,model13])
        model22.setChildModels([model14,model15])

        model31.setChildModels([model21])
        model32.setChildModels([model22])
        model33.setChildModels([HZJTreeModel("model41")])
        let model = HZJTreeModel("model00").setOpenState(true)
        model.setChildModels([model31,model32,model33])
        
        
        
        let modela1 = HZJTreeModel2("modela1")
        let modela2 = HZJTreeModel2("modela2")
        let modela3 = HZJTreeModel2("modela3")
        
        let modelb1 = HZJTreeModel2("modelb1")
        
        modela1.setChildModels([modelb1])

        let modelc = HZJTreeModel2("modelc").toShowCurrent(true)
        modelc.setChildModels([modela1,modela2,modela3])
                
        tabV.setData([model,modelc])
    }
}
